package jp.tkym.labs.geom;

public class MatrixUtil {
	
	public static class Euler{
		public static Matrix3f zxz(double alpha, double beta, double gamma){
			return 	rotZ(gamma).multiply(
						rotX(beta).multiply(
							rotZ(alpha)
						)
					);
		}
	}
	
	static Matrix3f rotZ(double z){
		Matrix3f m = new Matrix3f();
//		if(withinLimits(z)) return m;
		m.r00 =	c(z);	m.r01 =-s(z); 	m.r02 = 0.0f;
		m.r10 =	s(z);	m.r11 = c(z); 	m.r12 = 0.0f;
		m.r20 =	0.0f;	m.r21 = 0.0f; 	m.r22 = 1.0f;
		return m;
	}
	
	static Matrix3f rotY(double y){
		Matrix3f m = new Matrix3f();
//		if(withinLimits(y)) return m;
		m.r00 =	c(y);	m.r01 = 0.0f; 	m.r02 = s(y);
		m.r10 =	0.0f;	m.r11 = 1.0f; 	m.r12 = 0.0f;
		m.r20 =-s(y);	m.r21 = 0.0f; 	m.r22 = c(y);
		return m;
	}

	static Matrix3f rotX(double x){
		Matrix3f m = new Matrix3f();
//		if(withinLimits(x)) return m;
		m.r00 =	1.0f;	m.r01 = 0.0f; 	m.r02 = 0.0f;
		m.r10 =	0.0f;	m.r11 = c(x); 	m.r12 =-s(x);
		m.r20 =	0.0f;	m.r21 = s(x); 	m.r22 = c(x);
		return m;
	}
	
	static boolean withinLimits(double x){
		if(x < 0.001f && x > -0.001f) return true;
		return false;
	}
	
	static float c(double x){
		return (float)Math.cos(x);
	}
	
	static float s(double x){
		return (float)Math.sin(x);
	}
}